package com.kelvem.saas.workbanch.core.manager.controller;

import com.kelvem.saas.workbanch.core.base.Page;
import com.kelvem.saas.workbanch.core.exception.SaasAssert;
import com.kelvem.saas.workbanch.core.manager.model.BizPageActionEntity;
import com.kelvem.saas.workbanch.core.manager.request.BizPageActionQueryVo;
import com.kelvem.saas.workbanch.core.manager.service.BizPageActionService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 业务页面行为控制层
 *
 * @author kelvem
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/bizPageAction")
public class BizPageActionController {

    @Resource
    private BizPageActionService bizPageActionService;
    
    /**
     * 增加业务页面行为
     * curl -X POST http://localhost:9090/bizPageAction/v1/add -H 'Content-Type: application/json' -d '{"id": null, "actionUuid": "action_uuid", "bizPageId": 1, "panelUuid": "panel_uuid", "nodeType": "node_type", "nodeUuid": "node_uuid", "metaTableId": 1, "eventName": "event_name", "actionType": "action_type", "actionSubType": "action_sub_type", "showFlag": 0, "sortNo": 6, "eventSourceType": "event_source_type", "relatedType": "related_type", "relatedId": 7, "relatedResource": "related_resource", "relatedJson": "related_json", "paramType": "param_type", "srcPanelList": "src_panel_list", "datasetName": "dataset_name", "createUid": "create_uid", "updateUid": "update_uid", "memo": "memo"}'
     *
     * @param bizPageAction 业务页面行为信息
     * @return Long 主键id
     */
    @PostMapping("/v1/add")
    public Long add(@RequestBody(required = false) BizPageActionEntity bizPageAction) {
        SaasAssert.notNull(bizPageAction);

        log.debug("BizPageActionController:add:start, bizPageAction=【{}】", bizPageAction);
        Long bizPageActionId = bizPageActionService.addBizPageAction(bizPageAction);
        log.debug("BizPageActionController:add:end, bizPageActionId={}", bizPageActionId);

        return bizPageActionId;
    }

    /**
     * 修改业务页面行为
     * curl -X PUT http://localhost:9090/bizPageAction/v1/update -H 'Content-Type: application/json' -d '{"id": 10000, "actionUuid": "action_uuid", "bizPageId": 1, "panelUuid": "panel_uuid", "nodeType": "node_type", "nodeUuid": "node_uuid", "metaTableId": 1, "eventName": "event_name", "actionType": "action_type", "actionSubType": "action_sub_type", "showFlag": 0, "sortNo": 6, "eventSourceType": "event_source_type", "relatedType": "related_type", "relatedId": 7, "relatedResource": "related_resource", "relatedJson": "related_json", "paramType": "param_type", "srcPanelList": "src_panel_list", "datasetName": "dataset_name", "createUid": "create_uid", "updateUid": "update_uid", "memo": "memo"}'
     *
     * @param bizPageAction 业务页面行为信息
     * @return Integer 修改记录数
     */
    @PostMapping("/v1/update")
    public Integer update(@RequestBody(required = false) BizPageActionEntity bizPageAction) {
        SaasAssert.notNull(bizPageAction);

        log.debug("BizPageActionController:update:start, bizPageAction=【{}】", bizPageAction);
        int count = bizPageActionService.updateBizPageAction(bizPageAction);
        log.debug("BizPageActionController:update:end, count={}", count);

        return count;
    }

    /**
     * 删除业务页面行为
     * curl -X DELETE 'http://localhost:9090/bizPageAction/v1/delete/10002'
     *
     * @param bizPageActionId 业务页面行为id
     * @return Integer 删除记录数
     */
    @PostMapping("/v1/delete/{bizPageActionId}")
    public Integer delete(@PathVariable(required = false) Long bizPageActionId) {
        SaasAssert.notNull(bizPageActionId);

        log.debug("BizPageActionController:delete:start, bizPageActionId={}", bizPageActionId);
        int count = bizPageActionService.deleteBizPageAction(bizPageActionId);
        log.debug("BizPageActionController:delete:end, count={}", count);

        return count;
    }

    /**
     * 查询业务页面行为分页数据
     * curl -X POST http://localhost:9090/bizPageAction/v1/queryPage -H 'Content-Type: application/json' -d '{"id": 10000}'
     *
     * @param bizPageActionQueryVo 查询用
     * @return Page<BizPageActionEntity> 业务页面行为分页数据
     */
    @PostMapping("/v1/queryPage")
    public Page<BizPageActionEntity> queryPage(@RequestBody(required = false) BizPageActionQueryVo bizPageActionQueryVo) {
        SaasAssert.notNull(bizPageActionQueryVo);

        log.debug("BizPageActionController:queryPage:start, bizPageActionQueryVo=【{}】", bizPageActionQueryVo);
        Page<BizPageActionEntity> page = bizPageActionService.queryBizPageActionPage(bizPageActionQueryVo);
        log.debug("BizPageActionController:queryPage:end, page.count={}", page.getSize());

        return page;
    }

    /**
     * 根据id查业务页面行为信息
     * curl -X GET 'http://localhost:9090/bizPageAction/v1/get/10000'
     *
     * @param bizPageActionId 业务页面行为id
     * @return BizPageAction 业务页面行为信息
     */
    @GetMapping("/v1/get/{bizPageActionId}")
    public BizPageActionEntity getById(@PathVariable(required = false) Long bizPageActionId) {
        SaasAssert.notNull(bizPageActionId);

        log.debug("BizPageActionController:getById:start, bizPageActionId={}", bizPageActionId);
        BizPageActionEntity bizPageAction = bizPageActionService.getBizPageActionById(bizPageActionId);
        log.debug("BizPageActionController:getById:end, bizPageAction=【{}】", bizPageAction);

        return bizPageAction;
    }
    
}
